#!/usr/bin/python
# -*- coding: utf-8 -*-

from web.request import Request
from web.response import Response
from manager.employee_manager import EmployeeManager
import web.page
import utils.common

class Stats(object):
    @utils.common.auth
    def handle(self, req, resp):  
        args = web.page.set_navbar_token(req, True)
        output = web.page.render('stats.html', args) 
        return resp.respond(output)

class StatsHandler(object):
    @utils.common.auth
    @utils.common.check_token
    def handle(self, req, resp):  
        manager = EmployeeManager()
        args = req.args
        if not args.get('name') and not args.get('gender') and not args.get('deptid') :
            deptlist = manager.query_dept()
            if len(deptlist) > 0:
                args = {'depts': deptlist, 'deptvisible':'visibility:visible'}
            else:
                args = {'depts': deptlist, 'empty':u'没有找到数据，清注意查询条件。'}
        else:
            emplist = manager.query_cond(req.args)
            if len(emplist) > 0:
                args = {'emps': emplist, 'empvisible':'visibility:visible'}
            else:
                args = {'emps': emplist, 'empty':u'没有找到数据，清注意查询条件。'}
        args.update(web.page.set_navbar_token(req, True))
        output = web.page.render('stats.html', args)
        return resp.respond(output)

